Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

feat: replace legacyInstamine option with instamine=eager|strict #2013

Merged
merged 16 commits into from
Jan 11, 2022

Conversation

davidmurdoch
Copy link
Member

No description provided.

// ```
// If we don't have this delay here the messages will be sent before
// the call has a chance to listen to the event.
setImmediate(async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out this was broken in greedy mode!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is broken?

Copy link
Member Author

@davidmurdoch davidmurdoch Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay wasn't working. Our existing tests caught it when I switched the default.

await provider.send("eth_sendTransaction", ...);
await provider.once("message"); // <- this wasn't work, but it should.

// first mine operation to be fully complete.
await emitBlockProm;
}
this.emit("block", finalizedBlockData);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to wait because evm_mine and miner_start wait on their own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel it necessary to explain this in the review it likely belongs as a comment in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It explains why the old code was removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually having to revisit this because I noticed if someone sends stops the miner via miner_stop, send enough transactions to fill two blocks, then calls miner_start, all pending transactions aren't mined before miner_start returns... which is what we want.

I think evm_mine suffers from a similar issue, but I haven't yet figured out what yet.

These issues might be rare enough that I can wait until after v7 stable to fix them, as it might take a bit of refactoring to get the timings correct.

Comment on lines +529 to +533
const [finalLaterTxsReceipts, finalLaterTxsTransactions] =
await Promise.all([
finalLaterTxsReceiptsProm,
finalLaterTxsTransactionsProm
]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

Comment on lines +103 to +106
const { status, blockNumber } = await provider.send(
"eth_getTransactionReceipt",
[txHash]
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

@@ -75,8 +75,7 @@ describe("api", () => {
extraData: "0x",
gasLimit: gasLimit,
gasUsed: "0x0",
hash:
"0xe2c5d64b9e17e25abc0589c378b77adecf06668dd3c073ab9c53dec51baf2048",
hash: "0xe2c5d64b9e17e25abc0589c378b77adecf06668dd3c073ab9c53dec51baf2048",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

Comment on lines +80 to +83
const result = await strictInstamineProvider.send(
"eth_getTransactionReceipt",
[hash]
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

Comment on lines +1437 to +1443
const { gas, structLogs, returnValue, storage } =
await this.#traceTransaction(
newBlock.transactions[transaction.index.toNumber()],
trie,
newBlock,
options
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

Comment on lines +330 to +331
blocks.earliest = blocks.latest =
await this.#blockBeingSavedPromise.then(({ block }) => block);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(prettier change)

src/chains/ethereum/ethereum/src/blockchain.ts Outdated Show resolved Hide resolved
Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments as questions mostly. Not a fan of greedy and strict.

src/chains/ethereum/ethereum/src/api.ts Show resolved Hide resolved
// first mine operation to be fully complete.
await emitBlockProm;
}
this.emit("block", finalizedBlockData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel it necessary to explain this in the review it likely belongs as a comment in the code.

src/chains/ethereum/ethereum/tests/helpers/getProvider.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/tests/helpers/getProvider.ts Outdated Show resolved Hide resolved
@davidmurdoch davidmurdoch changed the title feat: replace legacyInstamine option with `instamine=greedy|strict feat: replace legacyInstamine option with instamine=greedy|strict Jan 7, 2022
@davidmurdoch davidmurdoch changed the title feat: replace legacyInstamine option with instamine=greedy|strict feat: replace legacyInstamine option with instamine=eager|strict Jan 7, 2022
Copy link
Contributor

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more change request I couldn't make in the code - can we rename greedyInstamining.test.ts since we're not calling it that anymore?

src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/blockchain.ts Outdated Show resolved Hide resolved
options.logging = options.logging || { logger: { log: () => {} } };

// set `asyncRequestProcessing` to `true` by default
let doAsync = options.chain.asyncRequestProcessing;
doAsync = options.chain.asyncRequestProcessing =
doAsync != null ? doAsync : true;

// don't write to stdout in tests
if (!options.logging.logger) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't appear to actually do anything in our tests (I replaced it with throw new Error... and all tests still passed)

* the transaction's hash is returned to the caller. If `legacyInstamine` is
* `true`, `blockTime` must be `0` (default).
* Set the instamine mode to either "eager" (default) or "strict".
* * In "eager" mode a transaction will be included in a block before the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * In "eager" mode a transaction will be included in a block before the
* * In "eager" mode a transaction will be included in a block before

*
* @defaultValue false
* @deprecated Will be removed in v4
* @defaultValue eager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @defaultValue eager
* @defaultValue "eager"

legacyName: "legacyInstamine",
cliType: "boolean"
cliDescription: `Set the instamine mode to either "eager" (default) or "strict".
* In "eager" mode a transaction will be included in a block before the its hash is returned to the caller.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* In "eager" mode a transaction will be included in a block before the its hash is returned to the caller.
* In "eager" mode a transaction will be included in a block before its hash is returned to the caller.

@davidmurdoch davidmurdoch merged commit c32aee8 into develop Jan 11, 2022
@davidmurdoch davidmurdoch deleted the instamine branch January 11, 2022 17:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants